package com.konne.nightmare.FastPublicOpinion.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.bigkoo.pickerview.adapter.ArrayWheelAdapter;
import com.blankj.utilcode.util.SizeUtils;
import com.blankj.utilcode.util.StringUtils;
import com.contrarywind.view.WheelView;
import com.konne.nightmare.FastPublicOpinion.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Create by ws.
 * on Data:2022/2/11  Time:下午 1:49.
 * description: ** .
 */
public class TimeSelDialog extends Dialog {
    private List<String> datas;
    private TimeSelectListener timeSelectListener;
    private String title;
    public TimeSelDialog(@NonNull Context context) {
        super(context, R.style.ActionSheetDialogStyle);
    }

    public TimeSelDialog setTitle(String title) {
        this.title = title;
        return this;
    }

    public TimeSelDialog setDatas(List<String> datas) {
        this.datas = datas;
        return this;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_time_selector);
        Window dialogWindow = getWindow();
     //   dialogWindow.setBackgroundDrawableResource(android.R.color.transparent);
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
        lp.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        dialogWindow.setAttributes(lp);
        dialogWindow.setGravity(Gravity.BOTTOM);
        if(datas==null || datas.isEmpty()){
            initDefData();
        }
        if(StringUtils.isEmpty(title)){
            TextView tv_title=findViewById(R.id.tv_title);
            tv_title.setText(title);
        }
        initView();
    }

    public TimeSelDialog setTimeSelectListener(TimeSelectListener timeSelectListener) {
        this.timeSelectListener = timeSelectListener;
        return this;
    }

    private void initDefData() {
        datas=new ArrayList<>();
        datas.add("不限制");
        datas.add("2021 11 27  19 41");
        datas.add("2022 11 27  19 41");
        datas.add("2023 11 27  19 41");
        datas.add("2024 11 27  19 41");
        datas.add("2025 11 27  19 41");
        datas.add("2026 11 27  19 41");
        datas.add("2027 11 27  19 41");
        datas.add("2028 11 27  19 41");
        datas.add("2029 11 27  19 41");
        datas.add("2030 11 27  19 41");
        datas.add("2031 11 27  19 41");
        datas.add("2032 11 27  19 41");
    }

    private void initView() {
        WheelView wv_time=findViewById(R.id.wv_time);
        wv_time.setTextColorCenter(0xff3396FE);
        wv_time.setTextColorOut(0xff344854);
        wv_time.setDividerColor(Color.TRANSPARENT);
        wv_time.setGravity(Gravity.CENTER);
        wv_time.setLineSpacingMultiplier(2f);
        wv_time.setAdapter(new ArrayWheelAdapter(datas));
        findViewById(R.id.stv_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
        findViewById(R.id.stv_submit).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
                if(timeSelectListener!=null){
                    timeSelectListener.timeSelect(datas.get(wv_time.getCurrentItem()));
                }
            }
        });
    }
    public interface TimeSelectListener{
        void timeSelect(String str);
    }
}
